<%@ page language="java" pageEncoding="utf-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
  <head>
  
<%

  	String cpath = request.getContextPath();
  		String basePath = request.getScheme() + "://"
  				+ request.getServerName() + ":"
  				+ request.getServerPort() + cpath + "/";
%>

  
    <html:base />
    
    <title>materialGroupDetail</title>
<style type="text/css">
<!--
.apDiv {
	position:absolute;
	width:160px;
	height:60px;
	z-index:1;
	background-color: #FFFFFF;
	visibility: hidden;
}
.desDiv {
	position:absolute;
	width:300px;
	height:100px;
	z-index:1;
	background-color: #FFFFFF;
	visibility: hidden;
}

-->
</style>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script language="javascript">
	var downloadURL;
		function doDownload(){
			window.open(downloadURL+"?isDownload=1",null,null,null);
		}
		
function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

	function keyWord(value)
			{
				
				var data = value.split(" ");
				
				var result="" ;
				for(i=0;i<data.length;i++)
				{
			
					result=result+"<a href='queryKey.do?key=" + data[i]+"'>"+data[i]+ "</a> "
				}
				return result;
			}
	
	var xhr = false ;
	var currentId ;
	function createXHR(){
	
  		 try {
    		 xhr = new XMLHttpRequest();
  		 } 
  		 catch (trymicrosoft) {
  		   try {
  		     xhr = new ActiveXObject("Msxml2.XMLHTTP");
 		    } 
 		    catch (othermicrosoft) {
 		      try {
 		        xhr = new ActiveXObject("Microsoft.XMLHTTP");
 		      }
 		       catch (failed) {
 		        xhr = false;
 		      }  
  		   }
 		  }
 		  if (!xhr)
  		   alert("Error initializing XMLHttpRequest!");

	}		
	function updateKeyWord(id)
	{
		currentId = id;
		var targetId = "textfield"+id ;
		var obj = document.getElementById(targetId);
		if (obj!=null){
			createXHR();
			xhr.open("POST","<%=basePath %>detail/modify.do?",true);
			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
			xhr.onreadystatechange=handleReadyState;
			xhr.send("Type=Material&ObjectID="+id+"&keyWord="+obj.value);
		}
	}
	function updateDes(id)
	{
		currentId = id ;
		var targetId = "textdesc"+id;
		var obj = document.getElementById(targetId);
		if (obj!=null){
			createXHR();
			xhr.open("POST","<%=basePath %>detail/modify.do?",true);
			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
			xhr.onreadystatechange=handleReadyState;
			xhr.send("Type=Material&ObjectID="+id+"&description="+obj.value);
		}
	}
	function handleReadyState(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				parseResult();					
			}
		}
	}
	function parseResult()
	{

		var unitDataString =  xhr.responseText;
		var messageobj = document.getElementById("message"+currentId);
		var desmessageobj = document.getElementById("desmessage"+currentId);
		if (unitDataString == "KeySuccess")
		{		
			var srcobj = document.getElementById("textfield"+currentId);
			var obj    = document.getElementById("keyWord"+currentId);
			if (obj!=null && srcobj!=null)
			{	
				obj.innerHTML=keyWord(srcobj.value);	
			}
			messageobj.color="red";
			messageobj.innerHTML ="";
			MM_showHideLayers('apDiv'+currentId,'','hide');
		}
		else if(unitDataString == "DesSuccess")
		{
			var srcobj = document.getElementById("textdesc"+currentId);
			var obj    = document.getElementById("description"+currentId);
			if (obj!=null && srcobj!=null)
			{	
				obj.innerHTML=srcobj.value;	
			}
			
			messageobj.innerHTML ="";
			MM_showHideLayers('desDiv'+currentId,'','hide');
		}
		else{
					
			messageobj.color="red";
			messageobj.innerHTML = xhr.responseText;
			desmessageobj.color="red";
			desmessageobj.innerHTML=xhr.responseText;
			
		}
	}
	
	function Query()
	{
		var key = document.getElementById("queryKey")
		if (key!=null)
		{
		    
			var url = "queryKey.do?key="+key.value;
			window.location.href=url;
		}
	}
</script>
  </head>
  
  <body>
  <logic:notEmpty name="materialGroupId">
    <table>
    <tr>
    <logic:equal name="hasMaterial" value="false" >
    <td>
      <html:form action="/materialAdd">
      	<html:hidden property="type" value="Materialgroup"/>
      	<input type="hidden" name="parentId" value='<bean:write name="materialGroupId"/>'>
      	<html:text property="name"/>
      	<html:submit>添加素材类型</html:submit>
      </html:form>
    </td>
    </logic:equal>
    <logic:equal name="hasMaterialGroup" value="false" >
    <td>
      <html:form action="/materialAdd">
      	<html:hidden property="type" value="Material"/>
      	<input type="hidden" name="parentId" value='<bean:write name="materialGroupId" />'>
      	<html:text property="name"/>
      	<html:submit>添加素材</html:submit>
      </html:form>
    </td>
    </logic:equal>
    </tr>
    </table>
    </logic:notEmpty>
	<logic:equal name="hasMaterialGroup" value="true" >
		<logic:notEmpty name="materialgroups">
			<table border="1">
				<tr>
					<td>
						MaterialGroup
					</td>
				</tr>
				<logic:iterate id="element" name="materialgroups">
					<tr>
						<td>
							<bean:write name="element" property="materialGroupName" />
						</td>
						<td>
							<a
								href='delete.do?type=Materialgroup&objectId=<bean:write name="element" property="materialGroupId"/>'
								onclick="return   confirm('Confirm Delete')">[delete]</a>
						</td>
					</tr>
				</logic:iterate>
			</table>
		</logic:notEmpty>
	</logic:equal>
    
    
	<logic:equal name="hasMaterial" value="true" >
	
      <table border="1" width="100%">
       <tr><td colspan="3">Material</td></tr>
       <tr><td colspan="3">
       		<input type="text"  id="queryKey" value="">
       		<input type="button" id ="query" value="查询" onclick="Query()"/>	
       </td></tr>
        <logic:iterate id="element2" name="materials" >
        
       		<tr>
        	  <td><a href='javascript:toMaterial(<bean:write name="element2" property="materialId"/>)'><bean:write name="element2" property="materialName"/></a></td>
        	  <td><bean:write name="element2" property="reguser.regName"/></td>
       	      <td><bean:write name="element2" property="inputTime" format="yyyy-MM-dd"/></td>
       	    </tr>
       	    <tr>
       	    <td colspan="3">
       	    <table width="100%" id="detail<bean:write name="element2" property="materialId"/>" border="1" style="display:none">
       	    	<tr>
       	    		<td colspan="5" id="description<bean:write name="element2" property="materialId"/>"><bean:write name="element2" property="description"/></td>
       	    	</tr>
       	    	<tr>
       	      		<td><a  href="javascript:AddFile(<bean:write name="element2" property="materialId"/>);">[AddFile]</a></td>
       	    		<td><a href='delete.do?type=Material&objectId=<bean:write name="element2" property="materialId"/>' onclick="return   confirm('Confirm Delete')">[delete]</a></td>
       	    		<td><a href='javascript:MM_showHideLayers("desDiv<bean:write name="element2" property="materialId"/>","","show")'>[Modify]</a></td>
       	    		
					<td align="right"><a href='javascript:MM_showHideLayers("apDiv<bean:write name="element2" property="materialId"/>","","show")'>[KeyWord]:</a></td>
					<td>&nbsp;
						<div id="apDiv<bean:write name="element2" property="materialId"/>" class="apDiv">
							<input name="textfield" type="text" id="textfield<bean:write name="element2" property="materialId"/>" value="<bean:write name="element2" property="keyWord"/>" />
							<br />
							<font id="message<bean:write name="element2" property="materialId"/>" >使用空格分隔</font>							
							<br/>
							<input name="button" type="submit" 
								onclick="updateKeyWord('<bean:write name="element2" property="materialId"/>')"
								value="save" />

							<input name="button2" type="submit" 
								onclick="MM_showHideLayers('apDiv<bean:write name="element2" property="materialId"/>','','hide')"
								value="cancel" />
						</div>
						<span id="keyWord<bean:write name="element2" property="materialId"/>">
						    
							<script language=javascript>
								document.write( keyWord("<bean:write name="element2" property="keyWord"/>"));
							</script>
						</span>
					</td>
       	    	</tr>
       	    	<tr>
       	    		<td colspan="5">
       	    		<div id ="desDiv<bean:write name="element2" property="materialId"/>" class="desDiv" >
       	    			<textarea id="textdesc<bean:write name="element2" property="materialId"/>" cols="100%" rows="5"><bean:write name="element2" property="description"/></textarea>
       	    			<input name="button" type="submit" 
								onclick="updateDes('<bean:write name="element2" property="materialId"/>')"
								value="save" />

							<input name="button2" type="submit" 
								onclick="MM_showHideLayers('desDiv<bean:write name="element2" property="materialId"/>','','hide')"
								value="cancel" />
							<font id="desmessage<bean:write name="element2" property="materialId"/>" ></font>	
       	    		</div>
       	    		</td>
       	    	</tr>
       	    	<tr >
       	    		<td id="AddFile<bean:write name="element2" property="materialId"/>" colspan="5" style="display:none">
       	    			
       	    		</td>
       	    	</tr>
       	    	
       	    </table>
       	    </td>
       	    </tr>
        </logic:iterate>
      </table>
      
      <table>
      		<tr>
      			<td>文件名称：</td>
      			<td id="fileName"></td>
      		</tr>
      		<tr>
      			<td>文件路径：</td>
      			<td id="filePath"></td>
      		</tr>
      		<tr>
      			<td>文件大小：</td>
      			<td id="fileSize"></td>
      		</tr>
      		<tr>
      			<td>文件像素：</td>
      			<td id="filePixel"></td>
      		</tr>
      		<tr>
      			<td>文件上传时间：</td>
      			<td id="lastModified"></td>
      		</tr>
      		<tr>
      			<td>下载：</td>
      			<td id="download"><input type="button" value="下载" onclick="doDownload();"></td>
      		</tr>
      	</table>
      </logic:equal>	
  </body>
  
<script language=javascript>
			var openId;
			
			function toMaterial(id){
				var targetId="detail"+id;
				var target=document.getElementById(targetId);
				if(id==openId){	
					if(target.style.display=="" || target.style.display=="block"){
						target.style.display="none";
						
					}else{
						target.style.display="";
						refreshB(id);
					}
				}else{
					closeAnother();
					target.style.display="";
					openId=id;
					refreshB(id);		
				}
			}
			
			var openFileId;
			function AddFile(id)
			{
				var targetId = "AddFile"+id;
				var target=document.getElementById(targetId);
				if (id==openFileId)
				{
					if(target.style.display==""|| target.style.display=="block")
					{
						target.style.display="none";
					}
					else
					{
						target.style.display="";
						
					}
				}
				else
				{
					var openFile=document.getElementById("AddFile"+openFileId);
					if(openFile!=null)
					{
						openFile.style.display="none";
					}
					target.style.display="";
					target.innerHTML="<iframe width='100%' src='intoUpload.do?materialId="+id+"'></iframe>"
					openFileId=id;
				}
			}
			
			
			function refreshB(id)
			{
				var value="Type=Material&amp;ObjectID="+id;
				if(navigator.appName=="Microsoft Internet Explorer"){
					top.B.location.href="<%=cpath%>/frame.do?Frame=12&Id=16&"+value;
				}else{
					value = value.replace(/&amp\;/g,"&");
					top.B.location.href="<%=cpath%>/frame.do?Frame=12&Id=16&"+value;
				}
			}
			
			function closeAnother(){
				var openTable=document.getElementById("detail"+openId);
				if(openTable!=null){
					openTable.style.display="none";
				}
			}
					
			
 </script>
</html:html>
